/*
 * @Author: rock
 * @Date: 2025-05-17 15:54:46
 * @LastEditors: rock 
 * @LastEditTime: 2025-05-23 17:47:19
 * @FilePath: /015Pool/002ThreadPool/include/Singleton.h
 * @Description: Ctrl+Num1-> For Document; Ctrl+Num2-> For Function
 * 
 * Copyright (c) 2025 by rock, All Rights Reserved. 
 */
#include <mutex>
#include <memory>

#include "global.h"

template<typename T>
class Singleton {
public:
    static T& getInstance() {
        static std::once_flag initFlag;
        std::call_once(initFlag, [](){
            instance_.reset(new T());
        });
        return *instance_;
    }

    Singleton(const Singleton&) = delete;
    Singleton& operator=(const Singleton&) = delete;

protected:
    Singleton() = default;
    ~Singleton() = default;

private:
    static std::unique_ptr<T> instance_;
};

template<typename T>
std::unique_ptr<T> Singleton<T>::instance_;
